package com.shzg.im.controller;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.shzg.im.model.ApiResult;
import com.shzg.im.model.User;
import com.shzg.im.service.GroupService;

@RestController
@RequestMapping("/group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    @RequestMapping("/members")
    public ApiResult getGroupMembers(@RequestParam String groupId) {
        ApiResult apiRst = new ApiResult();

        List<User> memLst = groupService.getGroupMemberListByGroupId(groupId);

        List<Map<String, Object>> rstMemLst = new LinkedList<Map<String, Object>>();

        for (User u : memLst) {
            Map<String, Object> memInfoMap = new LinkedHashMap<String, Object>();

            memInfoMap.put("id", u.getLogin_id());
            memInfoMap.put("name", u.getNick_name());
            memInfoMap.put("face", u.getAvatar());

            rstMemLst.add(memInfoMap);
        }

        apiRst.setObj(rstMemLst);

        return apiRst;
    }
}
